home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Appls / dpv / dpvmachine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-06  |  2.9 KB  |  211 lines  |  [TEXT/????]

  1. /* dpv -- ditroff previewer.  Ditroff virtual machine. */
  2.  
  3. #include "dpv.h"
  4. #include "dpvmachine.h"
  5. #include "dpvoutput.h"
  6.  
  7. /* Basic state */
  8.  
  9. int    size;        /* current point size */
  10. int    font;        /* current font */
  11. int    hpos;        /* horizontal position we are to be at next; left=0 */
  12. int    vpos;        /* current vertical position (down positive) */
  13.  
  14. /* Environment */
  15.  
  16.  
  17. struct    state    state[MAXSTATE];
  18. struct    state    *statep = state;
  19.  
  20. /* Mounted font table */
  21.  
  22. fontinfo fonts;
  23. int    nfonts = 0;    /* start with no fonts mounted */
  24.  
  25. /* Page info */
  26.  
  27. int    ipage;        /* internal page number */
  28.  
  29. /* Global info */
  30.  
  31. int    res = 432;    /* resolution for which input was prepared */
  32.             /* default is old troff resolution */
  33.  
  34. /* Load font info for font s on position n; optional file name s1 */
  35.  
  36. loadfont(n, s, s1)
  37.     int n;
  38.     char *s, *s1;
  39. {
  40.     if (n < 0 || n > NFONTS)
  41.         error(FATAL, "can't load font %d", n);
  42.     fonts.name[n]= strdup(s);
  43. }
  44.  
  45. /* Initialize device */
  46.  
  47. t_init()
  48. {
  49.     /* Start somewhere */
  50.     hpos = vpos = 0;
  51.     size= 10;
  52.     font= 1;
  53.     usefont();
  54. }
  55.  
  56. /* Begin a new block */
  57.  
  58. t_push()
  59. {
  60.     if (statep >= state+MAXSTATE)
  61.         error(FATAL, "{ nested too deep");
  62.     statep->ssize = size;
  63.     statep->sfont = font;
  64.     statep->shpos = hpos;
  65.     statep->svpos = vpos;
  66.     ++statep;
  67. }
  68.  
  69. /* Pop to previous state */
  70.  
  71. t_pop()
  72. {
  73.     if (--statep < state)
  74.         error(FATAL, "extra }");
  75.     size = statep->ssize;
  76.     font = statep->sfont;
  77.     hpos = statep->shpos;
  78.     vpos = statep->svpos;
  79.     usefont();
  80. }
  81.  
  82. /* Called at the start of a new page.
  83.    Returns < 0 if it is time to stop. */
  84.  
  85. int
  86. t_page(n)
  87.     int n;
  88. {
  89.     if (nextpage(n) < 0)
  90.         return -1;
  91.     vpos = hpos = 0;
  92.     usefont();
  93.     return 0;
  94. }
  95.  
  96. /* Do whatever for the end of a line */
  97.  
  98. t_newline()
  99. {
  100.     hpos = 0;    /* because we're now back at the left margin */
  101. }
  102.  
  103. /* Convert integer to internal size number */
  104.  
  105. t_size(n)
  106.     int n;
  107. {
  108.     return n;
  109. }
  110.  
  111. /* Set character height to n */
  112.  
  113. /*ARGSUSED*/
  114. t_charht(n)
  115.     int n;
  116. {
  117.     static bool warned;
  118.     if (!warned) {
  119.         error(WARNING, "Setting character height not implemented");
  120.         warned= TRUE;
  121.     }
  122. }
  123.  
  124. /* Set slant to n */
  125.  
  126. /*ARGSUSED*/
  127. t_slant(n)
  128.     int n;
  129. {
  130.     static bool warned;
  131.     if (!warned) {
  132.         error(WARNING, "Setting slant not implemented");
  133.         warned= TRUE;
  134.     }
  135. }
  136.  
  137. /* Convert string to font number */
  138.  
  139. t_font(s)
  140.     char *s;
  141. {
  142.     return atoi(s);
  143. }
  144.  
  145. /* Print string s as text */
  146.  
  147. t_text(s)
  148.     char *s;
  149. {
  150.     int c;
  151.     char str[100];
  152.     
  153.     /* XXX This function doesn't work any more since lastw is not set */
  154.  
  155.     while (c = *s++) {
  156.         if (c == '\\') {
  157.             switch (c = *s++) {
  158.             case '\\':
  159.             case 'e':
  160.                 put1('\\');
  161.                 break;
  162.             case '(':
  163.                 str[0] = *s++;
  164.                 str[1] = *s++;
  165.                 str[2] = EOS;
  166.                 put1s(str);
  167.                 break;
  168.             }
  169.         } else {
  170.             put1(c);
  171.         }
  172.         /*hmot(lastw);*/
  173.     }
  174. }
  175.  
  176. /* Reset; argument is 'p' for pause, 's' for start */
  177.  
  178. t_reset(c)
  179.     int c;
  180. {
  181.     if (c == 's')
  182.         lastpage();
  183. }
  184.  
  185. /* Absolute vertical motion to position n */
  186.  
  187. vgoto(n)
  188.     int n;
  189. {
  190.     vpos = n;
  191.     recheck();
  192. }
  193.  
  194. /* Set point size to n */
  195.  
  196. setsize(n)
  197. int n;
  198. {
  199.     size = n;
  200.     usefont();
  201. }
  202.  
  203. /* Set font to n */
  204.  
  205. setfont(n)
  206. int n;
  207. {
  208.     font = n;
  209.     usefont();
  210. }
  211.